package ch.zhaw.swp1.view.component;

import java.util.Calendar;
import java.util.Date;

/**
 * Day-Part of DatePicker
 * @author Daniel Tiefenauer
 */
public class DayPicker extends ValuePicker {

	/**
	 * Default value
	 */
	private static final long serialVersionUID = 1L;
	
	public static final int JANUARY = 1;
	public static final int FEBRUARY = 2;
	public static final int MARCH = 3;
	public static final int APRIL = 4;
	public static final int MAY = 5;
	public static final int JUNE = 6;
	public static final int JULY = 7;
	public static final int AUGUST = 8;
	public static final int SEPTEMBER = 9;
	public static final int OCTOBER = 10;
	public static final int NOVEMBER = 11;
	public static final int DECEMBER = 12;
	
	private static final int MAX_VALUE_JAN = 31;
	private static final int MAX_VALUE_FEB = 29;
	private static final int MAX_VALUE_MAR = 31;
	private static final int MAX_VALUE_APR = 30;
	private static final int MAX_VALUE_MAY = 31;
	private static final int MAX_VALUE_JUN = 30;
	private static final int MAX_VALUE_JUL = 31;
	private static final int MAX_VALUE_AUG = 31;
	private static final int MAX_VALUE_SEP = 30;
	private static final int MAX_VALUE_OCT = 31;
	private static final int MAX_VALUE_NOV = 30;
	private static final int MAX_VALUE_DEC = 31;
	
	
	/*************************************************************************************/
	// Constructors
	/*----------------------------------------------------------------------------------*/
	/**
	 * Default constructor with current month
	 */
	public DayPicker(){
		super();
	}
	
	/**
	 * Overloaded Constructor specifying a month
	 * @param date a date (only month will be used)
	 */
	public DayPicker(Date date){
		super(date);
	}

	/*************************************************************************************/
	// Methods
	/*----------------------------------------------------------------------------------*/
	public void setMonth(int month){
		cal.set(Calendar.MONTH, month);
		setMaxValue();
		setValues();
		setSelectedIndex(0);
	}
	
	@Override
	public void setMaxValue() {
		// set maximum days depending on month
		switch(cal.get(Calendar.MONTH)+1){
		case JANUARY:
			maxValue = MAX_VALUE_JAN;
			break;
		case FEBRUARY:
			maxValue = MAX_VALUE_FEB;
			break;
		case MARCH:
			maxValue = MAX_VALUE_MAR;
			break;
		case APRIL:
			maxValue = MAX_VALUE_APR;
			break;
		case MAY:
			maxValue = MAX_VALUE_MAY;
			break;
		case JUNE:
			maxValue = MAX_VALUE_JUN;
			break;
		case JULY:
			maxValue = MAX_VALUE_JUL;
			break;
		case AUGUST:
			maxValue = MAX_VALUE_AUG;
			break;
		case SEPTEMBER:
			maxValue = MAX_VALUE_SEP;
			break;
		case OCTOBER:
			maxValue = MAX_VALUE_OCT;
			break;
		case NOVEMBER:
			maxValue = MAX_VALUE_NOV;
			break;
		case DECEMBER:
			maxValue = MAX_VALUE_DEC;
			break;
		default:
			maxValue = 31;
			break;
		}
	}
	@Override
	public void setMinValue() {
		minValue = 1;
	}

}
